/**
 * @file		dd_pmc_temp_sensor_if.c
 * @brief		PMC Temperature Sensor IF driver
 * @note		None
 * @attention	None
 * 
 * <B><I>Copyright 2016 Socionext Inc.</I></B>
 */

#include "dd_pmc_temp_sensor_if.h"
#include "pmc.h"
#include "dd_arm.h"

/*----------------------------------------------------------------------*/
/* Definition															*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
#define dd_pmc_ts_if_dsb() Dd_ARM_Dsb_Pou()

/*----------------------------------------------------------------------*/
/* Enumeration															*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
// Nothing Special


/*----------------------------------------------------------------------*/
/* Structure															*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
// Nothing Special


/*----------------------------------------------------------------------*/
/* Global Data															*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
// Callback function pointer
static volatile VP_CALLBACK			gDD_PMC_TS_IF_CallBack	= NULL;

/*----------------------------------------------------------------------*/
/* Macro																*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
// Nothing Special

/*----------------------------------------------------------------------*/
/* Local Function														*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
/**
 * @brief  Temperature sensor#x Interrupt analysis.
 */
static VOID dd_pmc_ts_if_ts_int_analysis( VOID )
{
	union io_pmc_sensor_if_sensor_irqmask		ts_int_mask;
	union io_pmc_sensor_if_sensor_irqstatus		ts_int_st;

	ts_int_mask.word	= IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQMASK.word;
	ts_int_st.word		= IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQSTATUS.word;

	dd_pmc_ts_if_dsb();

	if( (ts_int_st.bit.LF_IRQSTATUS == 1) && (ts_int_mask.bit.LF_IRQMASK == 0) ){								/* pgr0872 */
		// Clear LF_IRQCLR.
		IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQCLR.word	= 0x00000001;
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_TS0 | D_DD_PMC_TS_IF_INT_STATUS_LF) );
		}
	}
	if( (ts_int_st.bit.LN_IRQSTATUS == 1) && (ts_int_mask.bit.LN_IRQMASK == 0) ){								/* pgr0872 */
		// Clear LN_IRQCLR.
		IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQCLR.word	= 0x00000002;
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_TS0 | D_DD_PMC_TS_IF_INT_STATUS_LN) );
		}
	}
	if( (ts_int_st.bit.HN_IRQSTATUS == 1) && (ts_int_mask.bit.HN_IRQMASK == 0) ){								/* pgr0872 */
		// Clear HN_IRQCLR.
		IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQCLR.word	= 0x00000004;
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_TS0 | D_DD_PMC_TS_IF_INT_STATUS_HN) );
		}
	}
	if( (ts_int_st.bit.HF_IRQSTATUS == 1) && (ts_int_mask.bit.HF_IRQMASK == 0) ){								/* pgr0872 */
		// Clear HF_IRQCLR.
		IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQCLR.word	= 0x00000008;
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_TS0 | D_DD_PMC_TS_IF_INT_STATUS_HF) );
		}
	}
}


/*----------------------------------------------------------------------*/
/* Grobal Function														*/
/*----------------------------------------------------------------------*/
//---------------------------- driver section ----------------------------
/**
 * @brief  Get macro information.
 * @param[out]	macro_info		Temperature sensor if macro parameter.
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_Macro_Info( T_DD_PMC_TS_IF_MACRO_INFO* const macro_info )
{
#ifdef CO_PARAM_CHECK
	if( macro_info == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_Macro_Info: input param error. macro_info is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	macro_info->ts_num		= IO_PMC.TEMP_SENSOR_IF.MACROINFO.bit.TS_NUM;
	macro_info->macro_rev	= IO_PMC.TEMP_SENSOR_IF.MACROINFO.bit.MACRO_REV;
	macro_info->macro_id	= IO_PMC.TEMP_SENSOR_IF.MACROINFO.bit.MACRO_ID;

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Set All sensors setting enablement simultaneously.
 * @param[in]	config		Temperature sensor if config information.
 */
VOID Dd_PMC_TS_IF_Set_All_Config( E_DD_PMC_TS_IF_CONFIG config )
{
	// Set ALLCONFIG.
	IO_PMC.TEMP_SENSOR_IF.ALLCONFIG.word = config;

	dd_pmc_ts_if_dsb();
}

/**
 * @brief  Get All sensors setting enablement simultaneously.
 * @param[out]	config		Temperature sensor if config information.
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_Config_Mode( E_DD_PMC_TS_IF_CONFIG* const config )
{
#ifdef CO_PARAM_CHECK
	if( config == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_Config_Mode: input param error. config is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	if( IO_PMC.TEMP_SENSOR_IF.ALLCONFIG.word ){
		*config = E_DD_PMC_TS_IF_CONFIG_ALL_SETTING;	// all sensor setting
	}
	else{
		*config = E_DD_PMC_TS_IF_CONFIG_EACH_SETTING;	// each sensor individually set
	}

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Set Reset.
 * @param[in]	ts_type		Temperature Sensor IF type.<br>
 *							<ul><li>@ref E_DD_PMC_TS_IF_TYPE_ALL
 *								<li>@ref E_DD_PMC_TS_IF_TYPE_TS0</ul>
 * @param[in]	reset		Reset setting.<br>
 *							0:reset enablement<br>
 *							1:reset release
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR/D_DD_PMC_TS_IF_STATUS_ABNORMAL
 */
INT32 Dd_PMC_TS_IF_Reset( E_DD_PMC_TS_IF_TYPE ts_type, UCHAR reset )
{
#ifdef CO_PARAM_CHECK
	if((reset != 0) && (reset != 1)){
		Ddim_Assertion(("Dd_PMC_TS_IF_Reset: input param error. reset=%d\n", reset));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif
	
	if (ts_type == E_DD_PMC_TS_IF_TYPE_ALL) {
		// all sensor setting.
		if (IO_PMC.TEMP_SENSOR_IF.ALLCONFIG.bit.CONFIG_EN == E_DD_PMC_TS_IF_CONFIG_ALL_SETTING) {
			// Set TS_RESET.
			IO_PMC.TEMP_SENSOR_IF.TS_RESET.word = reset;
		}
		else {
			Ddim_Print(("Dd_PMC_TS_IF_Reset: ALL_CONFIG.CONFIG_EN is invalid.\n"));
			return D_DD_PMC_TS_IF_STATUS_ABNORMAL;
		}
	}
	else {
		// Set TS_RESET#0
		IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_RESET.word = reset;
	}
	
	dd_pmc_ts_if_dsb();
	
	return D_DDIM_OK;
}

/**
 * @brief  Set control information of all Sensors.
 * @param[in]	ctrl_all		Temperature Sensor all setting parameter
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Set_Control_All_Sensors( T_DD_PMC_TS_IF_ALL const *const ctrl_all )
{
	union	io_pmc_sensor_if_irqmask irq_mask;
#ifdef CO_PARAM_CHECK
	if( ctrl_all == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Set_Control_All_Sensors: input param error. ctrl_all is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif
	// reset
	IO_PMC.TEMP_SENSOR_IF.TS_RESET.word	= 0;
	// reset release
	IO_PMC.TEMP_SENSOR_IF.TS_RESET.word	= ctrl_all->ts_reset;

	//Config irq-mask paramter
	irq_mask.bit.TS0_IRQMASK				= ctrl_all->irq_mask.bit.ts_irq_0;
	irq_mask.bit.ALL_LF_IRQMASK				= ctrl_all->irq_mask.bit.all_lf_irq;
	irq_mask.bit.ALL_LN_IRQMASK				= ctrl_all->irq_mask.bit.all_ln_irq;
	irq_mask.bit.ALL_HN_IRQMASK				= ctrl_all->irq_mask.bit.all_hn_irq;
	irq_mask.bit.ALL_HF_IRQMASK				= ctrl_all->irq_mask.bit.all_hf_irq;
	irq_mask.bit.ANY_LF_IRQMASK				= ctrl_all->irq_mask.bit.any_lf_irq;
	irq_mask.bit.ANY_LN_IRQMASK				= ctrl_all->irq_mask.bit.any_ln_irq;
	irq_mask.bit.ANY_HN_IRQMASK				= ctrl_all->irq_mask.bit.any_hn_irq;
	irq_mask.bit.ANY_HF_IRQMASK				= ctrl_all->irq_mask.bit.any_hf_irq;
	IO_PMC.TEMP_SENSOR_IF.IRQMASK.word		= irq_mask.word;										/* pgr0872 */

	if (E_DD_PMC_TS_IF_CONFIG_ALL_SETTING == IO_PMC.TEMP_SENSOR_IF.ALLCONFIG.bit.CONFIG_EN) {
		// HI_FULL_TEMP/HI_NEAR_TEMP/LO_NEAR_TEMP/LO_FULL_TEMP/HYS_TEMP
		IO_PMC.TEMP_SENSOR_IF.HI_FULL_TEMP		= ctrl_all->hi_full_temp;
		IO_PMC.TEMP_SENSOR_IF.HI_NEAR_TEMP		= ctrl_all->hi_near_temp;
		IO_PMC.TEMP_SENSOR_IF.LO_NEAR_TEMP		= ctrl_all->lo_near_temp;
		IO_PMC.TEMP_SENSOR_IF.LO_FULL_TEMP		= ctrl_all->lo_full_temp;
		IO_PMC.TEMP_SENSOR_IF.HYS_TEMP.word		= ctrl_all->hys_temp;
		// CT, Measurement time setting
		IO_PMC.TEMP_SENSOR_IF.TS_CT.word		= ctrl_all->ts_ct;
		// enable
		IO_PMC.TEMP_SENSOR_IF.TS_EN.word		= ctrl_all->ts_en;
	}
	// callback setting
	gDD_PMC_TS_IF_CallBack					= ctrl_all->callback;

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Get control information of all Sensors.
 * @param[out]	ctrl_all		Temperature Sensor all setting parameter
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_Control_All_Sensors( T_DD_PMC_TS_IF_ALL* const ctrl_all )
{
	union	io_pmc_sensor_if_irqmask irq_mask;

#ifdef CO_PARAM_CHECK
	if( ctrl_all == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_Control_All_Sensor: input param error. ctrl_all is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	// HI_FULL_TEMP
	ctrl_all->hi_full_temp	= IO_PMC.TEMP_SENSOR_IF.HI_FULL_TEMP;
	// HI_NEAR_TEMP
	ctrl_all->hi_near_temp	= IO_PMC.TEMP_SENSOR_IF.HI_NEAR_TEMP;
	// LO_NEAR_TEMP
	ctrl_all->lo_near_temp	= IO_PMC.TEMP_SENSOR_IF.LO_NEAR_TEMP;
	// LO_FULL_TEMP
	ctrl_all->lo_full_temp	= IO_PMC.TEMP_SENSOR_IF.LO_FULL_TEMP;
	// HYS_TEMP
	ctrl_all->hys_temp		= IO_PMC.TEMP_SENSOR_IF.HYS_TEMP.word;
	// IRQMASK
	irq_mask.word						= IO_PMC.TEMP_SENSOR_IF.IRQMASK.word;
	ctrl_all->irq_mask.bit.ts_irq_0		= irq_mask.bit.TS0_IRQMASK;							/* pgr0872 */
	ctrl_all->irq_mask.bit.all_lf_irq	= irq_mask.bit.ALL_LF_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.all_ln_irq	= irq_mask.bit.ALL_LN_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.all_hn_irq	= irq_mask.bit.ALL_HN_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.all_hf_irq	= irq_mask.bit.ALL_HF_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.any_lf_irq	= irq_mask.bit.ANY_LF_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.any_ln_irq	= irq_mask.bit.ANY_LN_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.any_hn_irq	= irq_mask.bit.ANY_HN_IRQMASK;						/* pgr0872 */
	ctrl_all->irq_mask.bit.any_hf_irq	= irq_mask.bit.ANY_HF_IRQMASK;						/* pgr0872 */
	// CT
	ctrl_all->ts_ct				= IO_PMC.TEMP_SENSOR_IF.TS_CT.word;
	// enable
	ctrl_all->ts_en				= IO_PMC.TEMP_SENSOR_IF.TS_EN.word;
	// callback setting
	ctrl_all->callback			= gDD_PMC_TS_IF_CallBack;

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Set each sensor parameter.
 * @param[in]	ctrl_param		Temperature Sensor each setting parameter
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Set_Control_Each_Sensor( T_DD_PMC_TS_IF_EACH const *const ctrl_param )
{
	union	io_pmc_sensor_if_sensor_irqmask	irq_mask;

#ifdef CO_PARAM_CHECK
	if( ctrl_param == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Set_Control_Each_Sensor: input param error. ctrl_param is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif
	// reset
	IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_RESET.word	= 0;
	// reset release
	IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_RESET.word	= ctrl_param->ts_reset;

	//Config irq-mask paramter
	irq_mask.bit.HF_IRQMASK		= ctrl_param->irq_mask.bit.hf_irq;
	irq_mask.bit.HN_IRQMASK		= ctrl_param->irq_mask.bit.hn_irq;
	irq_mask.bit.LF_IRQMASK		= ctrl_param->irq_mask.bit.lf_irq;
	irq_mask.bit.LN_IRQMASK		= ctrl_param->irq_mask.bit.ln_irq;
	//Set IRQ Mask
	IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQMASK.word	= irq_mask.word;

	///Set Temperature parameters
	if ( E_DD_PMC_TS_IF_CONFIG_EACH_SETTING == IO_PMC.TEMP_SENSOR_IF.ALLCONFIG.bit.CONFIG_EN) {
		// HI_FULL_TEMP/HI_NEAR_TEMP/LO_NEAR_TEMP/LO_FULL_TEMP/HYS_TEMP
		IO_PMC.TEMP_SENSOR_IF.SENSOR.HI_FULL_TEMP	= ctrl_param->hi_full_temp;
		IO_PMC.TEMP_SENSOR_IF.SENSOR.HI_NEAR_TEMP	= ctrl_param->hi_near_temp;
		IO_PMC.TEMP_SENSOR_IF.SENSOR.LO_NEAR_TEMP	= ctrl_param->lo_near_temp;
		IO_PMC.TEMP_SENSOR_IF.SENSOR.LO_FULL_TEMP	= ctrl_param->lo_full_temp;
		IO_PMC.TEMP_SENSOR_IF.SENSOR.HYS_TEMP.word	= ctrl_param->hys_temp;
		// CT, Measurement time setting
		IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_CT.word		= ctrl_param->ts_ct;
		// enable
		IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_EN.word		= ctrl_param->ts_en;
	}
	// callback setting
	gDD_PMC_TS_IF_CallBack						= ctrl_param->callback;
	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Get each sensor parameter.
 * @param[out]	ctrl_param		Temperature Sensor each setting parameter
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_Control_Each_Sensor( T_DD_PMC_TS_IF_EACH* const ctrl_param )
{
	union	io_pmc_sensor_if_sensor_irqmask	irq_mask;

#ifdef CO_PARAM_CHECK
	if( ctrl_param == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_Control_Each_Sensor: input param error. ctrl_param is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	// HI_FULL_TEMP
	ctrl_param->hi_full_temp	= IO_PMC.TEMP_SENSOR_IF.SENSOR.HI_FULL_TEMP;
	// HI_NEAR_TEMP
	ctrl_param->hi_near_temp	= IO_PMC.TEMP_SENSOR_IF.SENSOR.HI_NEAR_TEMP;
	// LO_NEAR_TEMP
	ctrl_param->lo_near_temp	= IO_PMC.TEMP_SENSOR_IF.SENSOR.LO_NEAR_TEMP;
	// LO_FULL_TEMP
	ctrl_param->lo_full_temp	= IO_PMC.TEMP_SENSOR_IF.SENSOR.LO_FULL_TEMP;
	// HYS_TEMP
	ctrl_param->hys_temp		= IO_PMC.TEMP_SENSOR_IF.SENSOR.HYS_TEMP.word;
	// IRQMASK
	irq_mask.word				= IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQMASK.word;
	ctrl_param->irq_mask.bit.lf_irq		= irq_mask.bit.LF_IRQMASK;								/* pgr0872 */
	ctrl_param->irq_mask.bit.ln_irq		= irq_mask.bit.LN_IRQMASK;								/* pgr0872 */
	ctrl_param->irq_mask.bit.hn_irq		= irq_mask.bit.HN_IRQMASK;								/* pgr0872 */
	ctrl_param->irq_mask.bit.hf_irq		= irq_mask.bit.HF_IRQMASK;								/* pgr0872 */
	// CT
	ctrl_param->ts_ct			= IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_CT.word;
	// enable
	ctrl_param->ts_en			= IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_EN.word;
	// reset
	ctrl_param->ts_reset		= IO_PMC.TEMP_SENSOR_IF.SENSOR.TS_RESET.word;
	// callback setting
	ctrl_param->callback		= gDD_PMC_TS_IF_CallBack;

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Get TS Data information.
 * @param[out]	ts_data		Temperature Sensor IF sensor TS_DATA structure.
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_TS_Data( T_DD_PMC_TS_IF_TS_DATA* const ts_data )
{
#ifdef CO_PARAM_CHECK
	if( ts_data == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_Sensor_TS_Data: input param error. ts_data is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	ts_data->ts_data_valid		= IO_PMC.TEMP_SENSOR_IF.SENSOR.TSDATA_VALID.word;
	ts_data->ts_data			= IO_PMC.TEMP_SENSOR_IF.SENSOR.TSDATA;

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Get IRQOUT status information of all sensors.
 * @param[out]	irq_out		Temperature Sensor IRQOUT status.
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_IRQ_Out_Status_All_Sensors( U_DD_PMC_TS_IF_IRQ_ALL* const irq_out )
{
	union	io_pmc_sensor_if_irqout irq_out_info;

#ifdef CO_PARAM_CHECK
	if( irq_out == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_IRQ_Out_Status: input param error. irq_out is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	// IRQOUT
	irq_out_info.word			= IO_PMC.TEMP_SENSOR_IF.IRQOUT.word;
	irq_out->bit.ts_irq_0		= irq_out_info.bit.TS0_IRQOUT;								/* pgr0872 */
	irq_out->bit.all_lf_irq		= irq_out_info.bit.ALL_LF_IRQOUT;							/* pgr0872 */
	irq_out->bit.all_ln_irq		= irq_out_info.bit.ALL_LN_IRQOUT;							/* pgr0872 */
	irq_out->bit.all_hn_irq		= irq_out_info.bit.ALL_HN_IRQOUT;							/* pgr0872 */
	irq_out->bit.all_hf_irq		= irq_out_info.bit.ALL_HF_IRQOUT;							/* pgr0872 */
	irq_out->bit.any_lf_irq		= irq_out_info.bit.ANY_LF_IRQOUT;							/* pgr0872 */
	irq_out->bit.any_ln_irq		= irq_out_info.bit.ANY_LN_IRQOUT;							/* pgr0872 */
	irq_out->bit.any_hn_irq		= irq_out_info.bit.ANY_HN_IRQOUT;							/* pgr0872 */
	irq_out->bit.any_hf_irq		= irq_out_info.bit.ANY_HF_IRQOUT;							/* pgr0872 */

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  Get IRQOUT status information of Temperature Sensor#0.
 * @param[out]	irq_out		Temperature Sensor IRQOUT status parameter
 * @return		D_DDIM_OK/D_DD_PMC_TS_IF_INPUT_PARAM_ERR
 */
INT32 Dd_PMC_TS_IF_Get_IRQ_Out_Status_Each_Sensor( U_DD_PMC_TS_IF_IRQ_SENSOR* const irq_out )
{
	union	io_pmc_sensor_if_sensor_irqout irq_out_info;

#ifdef CO_PARAM_CHECK
	if( irq_out == NULL ){
		Ddim_Assertion(("Dd_PMC_TS_IF_Get_IRQ_Out_Status_Each_Sensor: input param error. irq_out is NULL.\n"));
		return D_DD_PMC_TS_IF_INPUT_PARAM_ERR;
	}
#endif

	// IRQOUT
	irq_out_info.word	= IO_PMC.TEMP_SENSOR_IF.SENSOR.IRQOUT.word;
	irq_out->bit.lf_irq	= irq_out_info.bit.LF_IRQOUT;										/* pgr0872 */
	irq_out->bit.ln_irq	= irq_out_info.bit.LN_IRQOUT;										/* pgr0872 */
	irq_out->bit.hn_irq	= irq_out_info.bit.HN_IRQOUT;										/* pgr0872 */
	irq_out->bit.hf_irq	= irq_out_info.bit.HF_IRQOUT;										/* pgr0872 */

	dd_pmc_ts_if_dsb();

	return D_DDIM_OK;
}

/**
 * @brief  The interruption flag is cleared, and the CallBack function is called.
 * @return VOID
 */
VOID Dd_PMC_TS_IF_Int_Handler( VOID )
{
	union io_pmc_sensor_if_irqmask		int_mask;
	union io_pmc_sensor_if_irqstatus	int_st;

	int_mask.word	= IO_PMC.TEMP_SENSOR_IF.IRQMASK.word;
	int_st.word		= IO_PMC.TEMP_SENSOR_IF.IRQSTATUS.word;

	dd_pmc_ts_if_dsb();

	if( (int_st.bit.TS0_IRQSTATUS == 1) && (int_mask.bit.TS0_IRQMASK == 0) ){								/* pgr0872 */
		// Temperature sensor#x Interrupt analysis.
		dd_pmc_ts_if_ts_int_analysis();
	}
	if ((int_st.bit.ALL_LF_IRQSTATUS == 1) && (int_mask.bit.ALL_LF_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x00010000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ALL | D_DD_PMC_TS_IF_INT_STATUS_LF) );
		}
	}
	if ((int_st.bit.ALL_LN_IRQSTATUS == 1) && (int_mask.bit.ALL_LN_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x00020000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ALL | D_DD_PMC_TS_IF_INT_STATUS_LN) );
		}
	}
	if ((int_st.bit.ALL_HN_IRQSTATUS == 1) && (int_mask.bit.ALL_HN_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x00040000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ALL | D_DD_PMC_TS_IF_INT_STATUS_HN) );
		}
	}
	if ((int_st.bit.ALL_HF_IRQSTATUS == 1) && (int_mask.bit.ALL_HF_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x00080000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ALL | D_DD_PMC_TS_IF_INT_STATUS_HF) );
		}
	}
	if ((int_st.bit.ANY_LF_IRQSTATUS == 1) && (int_mask.bit.ANY_LF_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x01000000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ANY | D_DD_PMC_TS_IF_INT_STATUS_LF) );
		}
	}
	if ((int_st.bit.ANY_LN_IRQSTATUS == 1) && (int_mask.bit.ANY_LN_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x02000000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ANY | D_DD_PMC_TS_IF_INT_STATUS_LN) );
		}
	}
	if ((int_st.bit.ANY_HN_IRQSTATUS == 1) && (int_mask.bit.ANY_HN_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x04000000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ANY | D_DD_PMC_TS_IF_INT_STATUS_HN) );
		}
	}
	if ((int_st.bit.ANY_HF_IRQSTATUS == 1) && (int_mask.bit.ANY_HF_IRQMASK == 0)){							/* pgr0872 */
		IO_PMC.TEMP_SENSOR_IF.IRQCLR.word	= 0x08000000;	// clear
		if( gDD_PMC_TS_IF_CallBack ){
			(*gDD_PMC_TS_IF_CallBack)( (D_DD_PMC_TS_IF_INT_TYPE_ANY | D_DD_PMC_TS_IF_INT_STATUS_LN) );
		}
	}
}


